<?php
/**
 * Copyright (c) 2014-2018, www.kuacg.com
 * All right reserved.
 *
 * @since LTS-181021
 * @package Cute
 * @author 酷ACG资源网
 * @date 2018/10/21 10:00
 * @link https://www.kuacg.com/23856.html
 */
?>
<?php

/**
 * Class DownWidget
 */
class DownWidget extends WP_Widget {
    function __construct() {
        parent::__construct(false, __('TT-下载浮窗小工具', 'tt'), array( 'description' => __('禁止添加，请在文章编辑页开启下载小工具', 'tt') ,'classname' => 'widget_downwidget wow bounceInRight'));
    }

    function widget($args, $instance) {
        // parent::widget($args, $instance); // TODO: Change the autogenerated stub
        // extract($args);
        wp_reset_postdata();
        $vm = SinglePostVM::getInstance(get_queried_object_id());
        if($vm->isCache && $vm->cacheTime) {
            echo '<!-- Down widget cached ' . $vm->cacheTime . ' -->';
        }
        $data = $vm->modelData;
        $post_embed_down_info = maybe_unserialize(get_post_meta($data->ID, 'tt_embed_down_info', true));
        $option = $post_embed_down_info[0];
        $demo_url = $post_embed_down_info[1];
        $file_version = $post_embed_down_info[2];
        $file_format = $post_embed_down_info[3];
        $file_size = $post_embed_down_info[4];
        $file_require = $post_embed_down_info[5];
        ?>
        <?php echo $args['before_widget']; ?>
                <h3 class="widget-title"><span>文章资源信息</span></h3>
                <a href="<?php echo tt_url_for('download', $data->ID);?>" target="_blank" class="down"><i class="tico tico-cloud-download"></i> 立即下载</a>
                <?php if ($demo_url) { ?>
					<a href="<?php echo $demo_url;?>" target="_blank" class="down erphp-demo" style=" margin-top: 0 !important; background: #69c15a !important; "><i class="tico tico-eye"></i> 演示地址</a>
				<?php }?>
				

				<table id="isa-edd-specs">
				  <tbody>
				    <tr>
				      <td>
				          <font>最近更新：</font>
				      </td>
				      <td>
				          <font><?php echo $data->modifieddiff; ?></font>
				      </td>
				    </tr>

				    <?php if($file_version){ ?>
				    <tr>
				      <td>
				        <font>当前版本：</font>
				      </td>
				      <td>
				        <font><?php echo $file_version; ?></font>
				      </td>
				    </tr>
				    <?php } ?>

					<?php if($file_format){ ?>
				    <tr>
				      <td>
				        <font>文件格式：</font>
				      </td>
				      <td>
				        <font><?php echo $file_format; ?></font>
				      </td>
				    </tr>
				    <?php } ?>

				    <?php if($file_size){ ?>
				    <tr>
				      <td>
				        <font>文件大小：</font>
				      </td>
				      <td>
				        <font><?php echo $file_size; ?></font>
				      </td>
				    </tr>
				    <?php } ?>
				    
				    <?php if($file_require){ ?>
				    <tr>
				      <td>
				        <font>安装要求：</font>
				      </td>
				      <td>
				        <font><?php echo $file_require; ?></font>
				      </td>
				    </tr>
				    <?php } ?>
				   
				    
				    
				  </tbody>
				</table>

        <?php echo $args['after_widget']; ?>
        <?php
    }

    function update($new_instance, $old_instance) {
        return $new_instance;
    }

    function form($instance) {
        ?>
        <p><?php _e('<strong>Warning: </strong>This widget has nothing to configure, and also do not use it', 'tt'); ?></p>
        <?php
    }
}

/* 注册小工具 */
if ( ! function_exists( 'tt_register_widget_down' ) ) {
    function tt_register_widget_down() {
        register_widget( 'DownWidget' );
    }
}
add_action( 'widgets_init', 'tt_register_widget_down' );